package com.learn.project2.controller.admin;


import com.learn.project2.model.bo.admin.topic.TopicCreateBO;
import com.learn.project2.model.bo.admin.topic.TopicUpdateBVO;
import com.learn.project2.model.vo.admin.topic.TopicCreateVO;
import com.learn.project2.model.vo.admin.topic.TopicListVO;
import com.learn.project2.model.vo.admin.topic.TopicReadVO;
import com.learn.project2.service.admin.topic.TopicService;
import com.learn.project2.utils.BaseParam;
import com.learn.project2.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author zhizhuke
 * @version 1.0
 * @description:
 * @date 2022-01-06 23-07
 */
@RestController
@RequestMapping("admin/topic")
public class TopicController {

    @Autowired
    TopicService topicService;

    /**
     * @description:
     * @param:
     * @return:
     * @author zhizhuke
     * @date: 2022-01-08 08:44
     */
  @RequiresPermissions(value = {"admin:topic:list"})
    @RequestMapping("list")
    public Result list(BaseParam param, String title, String subtitle) {
        TopicListVO topicListVO = topicService.list(param, title, subtitle);
        return Result.ok(topicListVO);
    }

    /**
     * @description:
     * @param:
     * @return:
     * @author zhizhuke
     * @date: 2022-01-08 08:45
     */
    @RequiresPermissions(value = {"admin:topic:create"})
    @RequestMapping("create")
    public Result create(@RequestBody TopicCreateBO topicCreateBO) {
        TopicCreateVO topicCreateVO = topicService.create(topicCreateBO);
        return Result.ok(topicCreateVO);
    }

    /**
     * @description:
     * @param:
     * @return:
     * @author zhizhuke
     * @date: 2022-01-08 08:45
     */
   @RequiresPermissions(value = {"admin:topic:read"})
    @RequestMapping("read")
    public Result read(Integer id) {
        TopicReadVO topicReadVO = topicService.read(id);
        return Result.ok(topicReadVO);
    }

    /**
     * @description:
     * @param:
     * @return:
     * @author zhizhuke
     * @date: 2022-01-08 08:45
     */
  @RequiresPermissions(value = {"admin:topic:update"})
    @RequestMapping("update")
    public Result update(@RequestBody TopicUpdateBVO topicUpdateBVO) {
        topicService.update(topicUpdateBVO);
        return Result.ok(topicUpdateBVO);
    }

    /**
     * @description:
     * @param:
     * @return:
     * @author zhizhuke
     * @date: 2022-01-08 09:03
     */
  @RequiresPermissions(value = {"admin:topic:delete"})
    @RequestMapping("delete")
    public Result delete(@RequestBody TopicUpdateBVO topicUpdateBVO) {
        topicService.delete(topicUpdateBVO);
        return Result.ok();
    }

}
